var server = require('../../../utils/server');
Page({
    data:{
        region: ['', '', ''],
        customItem: '全部',
        name:'',
        tel:'',
        addr:'',
        // yb:'',
        addrcode:[],
        is_default:true,
    },
    isDefault: false,
    nameChange: function (e) {
        var value = e.detail.value;
        this.setData({
            name: value
        });
    },
    addressChange: function (e) {
        var value = e.detail.value;
        this.setData({
            addr: value
        });
    },
    phoneChange: function (e) {

        var value = e.detail.value;

        this.setData({
            tel: value
        });
    },
    yzChange: function (e) {
        var value = e.detail.value;
        this.setData({
            yb: value
        });
    },
    bindRegionChange: function (e) {
        this.setData({
            region: e.detail.value,
            addrcode:e.detail.code
        })
    },
    submit(){
        if (this.data.name && this.data.region[0] && this.data.tel && this.data.addr ){
            let _params={
                username:getApp().globalData.username,
                token:getApp().globalData.token,
                name:this.data.name,
                mobile:this.data.tel,
                province: this.data.addrcode[0],
                city: this.data.addrcode[1],
                district: this.data.addrcode[2],
                address:this.data.addr,
                is_default: this.data.is_default
            }
            // server.postJSON('/person/addaddress',_params,res=>{
            //     if(res.data.status==200){
            //         wx.navigateTo({
            //             url: '../list/list'
            //         })
            //     }
            // })
          server.send('/person/addaddress','POST',_params).then(res=>{
            if (res.status == 200) {
                    wx.navigateTo({
                        url: '../list/list'
                    })
                }
          })
        }else{
            wx.showToast({
                title: '请填写完整数据',
                icon:'none'
            })
        }
        
    }
})